package org.dromara.admin.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 房源类型
 */
@Getter
@AllArgsConstructor
public enum BuildingType {

    ENTIRE("ENTIRE", "整租"),
    APARTMENT("APARTMENT", "公寓"),
    SHARED("SHARED", "合租");

    /**
     * 存库用的值
     */
    private final String code;

    /**
     * 前端展示用
     */
    private final String info;

    /**
     * 根据 code 获取枚举
     */
    public static BuildingType getByCode(String code) {
        for (BuildingType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型代码: " + code);
    }

    /**
     * 根据 info 获取枚举
     */
    public static BuildingType getByInfo(String info) {
        for (BuildingType type : values()) {
            if (type.getInfo().equals(info)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型: " + info);
    }
}
